from flask import g, Flask, session, jsonify
from flask_migrate import Migrate

import configs
from blueprints.admin import bp as admin_bp
from blueprints.api.admin import bp as api_admin_bp
from blueprints.api.crawl import bp as api_crawl_bp
from exts import db

Flask.jinja_options["variable_start_string"] = "%%"
Flask.jinja_options["variable_end_string"] = "%%"
app = Flask(__name__)

# app.app_context().push()
app.config.from_object(configs)
db.init_app(app)

app.register_blueprint(admin_bp)
app.register_blueprint(api_admin_bp)
app.register_blueprint(api_crawl_bp)

migrate = Migrate(app, db)


@app.route('/health', methods=['GET'])
def health():
    return jsonify({"success": True})


@app.before_request
def before_request():
    g.user = session.get("user")


if __name__ == '__main__':
    app.run(
        host='0.0.0.0',
        port=9000
    )
